import uvicorn
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates

from app.dongcai.index import router as dongcai_router
from app.eBooks.index import router as ebooks_router
from app.niuniu.index import router as niuniu_router
from app.xueqiu.index import router as xueqiu_router

templates = Jinja2Templates(directory="templates")
app = FastAPI(openapi_url=None)
app.mount("/static", StaticFiles(directory="static"), name="static")
app.include_router(xueqiu_router)
app.include_router(niuniu_router)
app.include_router(ebooks_router)
app.include_router(dongcai_router)
NIUNIU_HTML = None


# app.add_event_handler('startup', history.update)
# app.add_event_handler('startup', scheduler.start)


@app.get("/get_data", response_class=HTMLResponse)
async def get_data(request: Request):
    return templates.TemplateResponse(request=request, name="xueqiu.html", context={})


@app.get('/niuniu')
async def get_niuniu(request: Request):
    return templates.TemplateResponse(request=request, name="niuniu.html", context={})


@app.get("/ebooks", response_class=HTMLResponse)
async def get_ebooks(request: Request):
    return templates.TemplateResponse(request=request, name="eBooks.html", context={})


if __name__ == '__main__':
    uvicorn.run("main:app", host="0.0.0.0", port=40000, reload=True)
